package com.ruoyi.serverinfo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.io.File;

@Configuration
public class TshockFileConfig {

    // 文件上传根路径
    @Value("${tshock.file.upload-path}")
    private String uploadPath;

    // 访问文件的基础URL
    @Value("${tshock.file.access-base-url}")
    private String accessBaseUrl;

    // 头像存储子路径
    private static final String AVATAR_SUB_PATH = "avatar/";
    
    // 横幅存储子路径
    private static final String BANNER_SUB_PATH = "banner/";

    public String getUploadPath() {
        // 确保目录存在
        File file = new File(uploadPath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return uploadPath;
    }

    public String getAccessBaseUrl() {
        return accessBaseUrl;
    }

    public String getAvatarUploadPath() {
        String path = uploadPath + File.separator + AVATAR_SUB_PATH;
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        return path;
    }

    public String getBannerUploadPath() {
        String path = uploadPath + File.separator + BANNER_SUB_PATH;
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        return path;
    }

    public String getAvatarAccessUrl(String fileName) {
        return accessBaseUrl + "/" + AVATAR_SUB_PATH + fileName;
    }

    public String getBannerAccessUrl(String fileName) {
        return accessBaseUrl + "/" + BANNER_SUB_PATH + fileName;
    }
}
    